package com.odobenus.client.listener;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.odobenus.client.zk.ZooKeeperServiceRegistry;

public class StartListener implements ApplicationListener<ContextRefreshedEvent> {

	private ZooKeeperServiceRegistry zooKeeperServiceRegistry;
	private String applicationName;
	private String applicationDomain;
	private Boolean enableRemote;

	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		if (event.getApplicationContext().getParent() == null) {
			System.out.println("程序启动");
			if (enableRemote) {
				zooKeeperServiceRegistry.register(applicationName, applicationDomain);
			}
		}
	}

	public StartListener(ZooKeeperServiceRegistry zooKeeperServiceRegistry, String applicationName,
			String applicationDomain, Boolean enableRemote) {
		super();
		this.zooKeeperServiceRegistry = zooKeeperServiceRegistry;
		this.applicationName = applicationName;
		this.applicationDomain = applicationDomain;
		this.enableRemote = enableRemote;
	}

}